package com.happy.unitconvert.common.exception;

import com.happy.unitconvert.common.result.ResultCode;

/**
 * 业务异常类
 */
public class BusinessException extends RuntimeException {

  private final ResultCode resultCode;

  public BusinessException(ResultCode resultCode) {
    super(resultCode.getMessage());
    this.resultCode = resultCode;
  }

  public BusinessException(ResultCode resultCode, String message) {
    super(message);
    this.resultCode = resultCode;
  }

  public BusinessException(ResultCode resultCode, String message, Throwable cause) {
    super(message, cause);
    this.resultCode = resultCode;
  }

  public BusinessException(String message) {
    super(message);
    this.resultCode = ResultCode.BUSINESS_ERROR;
  }

  public BusinessException(String message, Throwable cause) {
    super(message, cause);
    this.resultCode = ResultCode.BUSINESS_ERROR;
  }

  public ResultCode getResultCode() {
    return resultCode;
  }

  /**
   * 快速创建业务异常的静态方法
   */
  public static BusinessException of(ResultCode resultCode) {
    return new BusinessException(resultCode);
  }

  public static BusinessException of(ResultCode resultCode, String message) {
    return new BusinessException(resultCode, message);
  }

  public static BusinessException of(String message) {
    return new BusinessException(message);
  }
}
